package com.fl.nettydemo.test;

import com.fl.nettydemo.server.AsynchronousService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Map;
import java.util.concurrent.*;

@EnableAsync
@Component
public class test1 {
    public static Map<Integer, String> map = new ConcurrentHashMap<>();

    public static boolean status = true;

    public static void main(String[] args) {
        if (status) {
            status = false;
            new Thread(() -> {
                LocalDateTime before = LocalDateTime.now();
                while (map.size() < 10) {
                    try {
                        TimeUnit.SECONDS.sleep(1);
                        long between = ChronoUnit.SECONDS.between(before, LocalDateTime.now());
                        System.out.println("正在计算接包数量...." + map.size() + "---" + between);
                        if (between > 2) {
                            System.out.println("获取包超时！");
                            status = true;
                            break;
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
                status = true;
            }).start();
        }
        for (int i = 0; i < 9; i++) {
            map.put(i, "数据" + i);
        }
    }

}
